﻿using System;
using KKSG;
using UnityEngine;
using XMainClient.UI;
using XMainClient.UI.UICommon;
using XUtliPoolLib;

namespace XMainClient
{
	// Token: 0x02001167 RID: 4455
	internal class Process_RpcC2G_DoEnterScene
	{
		// Token: 0x1700371A RID: 14106
		// (get) Token: 0x0600DA6F RID: 55919 RVA: 0x0032D4E8 File Offset: 0x0032B6E8
		public static uint runstate
		{
			get
			{
				return Process_RpcC2G_DoEnterScene._runstate;
			}
		}

		// Token: 0x0600DA70 RID: 55920 RVA: 0x0032D500 File Offset: 0x0032B700
		public static void OnReply(DoEnterSceneArg oArg, DoEnterSceneRes oRes)
		{
			if (oRes.errorcode == ErrorCode.ERR_INVALID_REQUEST)
			{
				XSingleton<XDebug>.singleton.AddErrorLog("RpcC2G_DoEnterScene ERR_INVALID_REQUEST!", null, null, null, null, null);
			}
			else
			{
                //KKSG.SceneCfg sceneCfg = roPtc.Data;
				{
					string outString = string.Format("DoEnterSceneRes -> fightgroup:{0}, face:{1}, pos:({2},{3},{4}),battlestamp:{5},specialstate:{6}", oRes.fightgroup, oRes.face, oRes.pos.x, oRes.pos.y, oRes.pos.z, oRes.battlestamp, oRes.specialstate);
					XSingleton<XDebug>.singleton.AddWarningLog(outString);

                    outString = "otherunits:";
                    XSingleton<XDebug>.singleton.AddWarningLog(outString);
                    foreach (var v in oRes.otherunits)
                    {
                        outString = string.Format("UnitAppearance -> uID:{0}, unitName:{1}, unitType:{2}", v.uID, v.unitName, v.unitType);
                        XSingleton<XDebug>.singleton.AddWarningLog(outString);
                    }
                }
                //bool flag2 = !XSingleton<XScene>.singleton.bSceneLoadedRpcSend;
                if (/*!flag2*/XSingleton<XScene>.singleton.bSceneLoadedRpcSend)
				{
					XSingleton<XScene>.singleton.bSceneServerReady = true;
					XSingleton<XScene>.singleton.bSceneLoadedRpcSend = false;
					XSingleton<XDebug>.singleton.AddLog("Enter scene ", XSingleton<XScene>.singleton.SceneID.ToString(), null, null, null, null, XDebugColor.XDebug_None);
					//bool flag3 = oRes.errorcode == ErrorCode.ERR_DOENTERSCENE_FAILED;
					if (oRes.errorcode == ErrorCode.ERR_DOENTERSCENE_FAILED)
					{
						XSingleton<XDebug>.singleton.AddLog("ERR_DOENTERSCENE_FAILED", null, null, null, null, null, XDebugColor.XDebug_None);
					}
					else
					{
						Process_RpcC2G_DoEnterScene._runstate = oRes.scenestate.runstate;
						Vector3 vector = new Vector3(oRes.pos.x, oRes.pos.y, oRes.pos.z);
						Vector3 vector2 = XSingleton<XCommon>.singleton.FloatToAngle(oRes.face);
						Vector3 face = XSingleton<XCommon>.singleton.FloatToAngle(oRes.initface);
						XSingleton<XEntityMgr>.singleton.Player.Attributes.OnFightGroupChange((XSingleton<XGame>.singleton.SyncModeValue != 0) ? oRes.fightgroup : 1U);
						XSingleton<XEntityMgr>.singleton.Player.Attributes.AppearAt = vector;
						XSingleton<XEntityMgr>.singleton.Player.Net.CorrectNet(vector, face, 0U, true);
						XBattleDocument.MiniMapSetRotation(oRes.initface);
						GameObject gameObject = GameObject.Find("Scene/BattlePoint");
						XSingleton<XScene>.singleton.BattleTargetPoint = ((gameObject != null) ? gameObject.transform.position : Vector3.zero);
						gameObject = GameObject.Find("Scene/NestPoint");
						XSingleton<XScene>.singleton.NestTargetPoint = ((gameObject != null) ? gameObject.transform.position : Vector3.zero);
						XSingleton<XScene>.singleton.GameCamera.Root_R_Y_Default = XSingleton<XEntityMgr>.singleton.Player.EngineObject.Rotation.eulerAngles.y;
						XSingleton<XScene>.singleton.GameCamera.Root_R_Y = XSingleton<XScene>.singleton.GameCamera.Root_R_Y_Default;
						//bool flag4 = XSingleton<XScene>.singleton.GameCamera.Wall != null;
						if (XSingleton<XScene>.singleton.GameCamera.Wall != null)
						{
							XSingleton<XScene>.singleton.GameCamera.Wall.TargetY = XSingleton<XScene>.singleton.GameCamera.Root_R_Y_Default;
						}
						//bool bSpectator = XSingleton<XScene>.singleton.bSpectator;
						if (XSingleton<XScene>.singleton.bSpectator)
						{
							XSingleton<XEntityMgr>.singleton.Puppets(XSingleton<XEntityMgr>.singleton.Player, true, true);
							XSingleton<XInput>.singleton.Freezed = true;
							XSingleton<XEntityMgr>.singleton.Player.Attributes.OnFightGroupChange(2U);
						}
						else
						{
							//bool flag5 = XSingleton<XEntityMgr>.singleton.Player.Nav != null;
							if (XSingleton<XEntityMgr>.singleton.Player.Nav != null)
							{
								XSingleton<XEntityMgr>.singleton.Player.Nav.Active();
							}
							//bool flag6 = XSingleton<XEntityMgr>.singleton.Player.AI != null;
							if (XSingleton<XEntityMgr>.singleton.Player.AI != null)
							{
								XSingleton<XEntityMgr>.singleton.Player.AI.Active();
							}
							bool flag7 = ((ulong)oRes.specialstate & (ulong)(1L << (XFastEnumIntEqualityComparer<UnitSpecialState>.ToInt(UnitSpecialState.Unit_Puppet) & 31))) > 0UL;
							bool flag8 = ((ulong)oRes.specialstate & (ulong)(1L << (XFastEnumIntEqualityComparer<UnitSpecialState>.ToInt(UnitSpecialState.Unit_Invisible) & 31))) > 0UL;
							if (flag7 || flag8)
							{
								XSingleton<XEntityMgr>.singleton.Player.UpdateSpecialStateFromServer(oRes.specialstate, uint.MaxValue);
							}
							else
							{
								XSingleton<XEntityMgr>.singleton.Player.Present.ShowUp();
							}
						}
						//bool bSpectator2 = XSingleton<XScene>.singleton.bSpectator;
						if (XSingleton<XScene>.singleton.bSpectator)
						{
							//zcg XSpectateSceneDocument specificDocument = XDocuments.GetSpecificDocument<XSpectateSceneDocument>(XSpectateSceneDocument.uuID);
							//zcg specificDocument.IsCrossServerBattle = oRes.is_cross;
						}
						else
						{
							XBattleDocument specificDocument2 = XDocuments.GetSpecificDocument<XBattleDocument>(XBattleDocument.uuID);
							specificDocument2.IsCrossServerBattle = oRes.is_cross;
						}
						for (int i = 0; i < XSingleton<XGame>.singleton.Doc.Components.Count; i++)
						{
							(XSingleton<XGame>.singleton.Doc.Components[i] as XDocComponent).OnEnterSceneFinally();
						}
						XOutlookHelper.SetStatusState(XSingleton<XEntityMgr>.singleton.Player.Attributes, XSingleton<XEntityMgr>.singleton.Player, oRes.state, true);
						XSingleton<XScene>.singleton.SceneStarted = oRes.scenestate.isready;
						if (!XSingleton<XScene>.singleton.SceneStarted && DlgBase<BattleMain, BattleMainBehaviour>.singleton.IsLoaded() && DlgBase<BattleMain, BattleMainBehaviour>.singleton.IsVisible())
						{
							DlgBase<BattleMain, BattleMainBehaviour>.singleton.uiBehaviour.m_PromptFrame.gameObject.SetActive(true);
							DlgBase<BattleMain, BattleMainBehaviour>.singleton.SetLoadingPrompt(null, false);
						}
						if (XSingleton<XScene>.singleton.bSpectator && oRes.iswatchend)
						{
							//zcg DlgBase<SpectateSceneView, SpectateSceneBehaviour>.singleton.ShowBackToMainCityTips();
						}
						XSingleton<XLevelFinishMgr>.singleton.LevelRewardToken = oRes.battlestamp;
						if (XSingleton<XScene>.singleton.IsViewGridScene)
						{
							XSingleton<XEntityMgr>.singleton.Player.Net.SetHallSequence();
						}
						if (XSingleton<XGame>.singleton.CurrentStage.Stage == EXStage.World)
						{
							XSingleton<XEntityMgr>.singleton.Player.Attributes.SecurityStatistics.OnStart();
						}
						XSingleton<XReconnection>.singleton.SetLoginReconnectFlag(oRes.lrdata != null);
						if (oRes.lrdata != null)
						{
							XSingleton<XReconnection>.singleton.StartLoginReconnectSync(oRes.lrdata, oRes.otherunits);
						}
						else
						{
							XSingleton<XReconnection>.singleton.StartEnterSceneSync(oRes.otherunits);
						}
					}
				}
			}
		}

		// Token: 0x0600DA71 RID: 55921 RVA: 0x000FEEFC File Offset: 0x000FD0FC
		public static void OnTimeout(DoEnterSceneArg oArg)
		{
		}

		// Token: 0x04006239 RID: 25145
		private static uint _runstate = 0U;
	}
}
